package cn.cs.controller;

import cn.cs.common.DateUtil;
import cn.cs.common.Dto;
import cn.cs.common.DtoUtil;
import cn.cs.common.IdWorker;
import cn.cs.pojo.RepOrder;
import cn.cs.service.RepairEvaluateService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/*
* 用户对维修工评论接口
* */
@RequestMapping("/cs_order/repairEvaluate")
@RestController
public class RepairEvaluateController {
    @Resource
    private RepairEvaluateService repairEvaluateService;


    /**
     * 用户提交评价
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("/wxApi/registerRepairEvaluate")
    @ResponseBody
    @Transactional
    public Dto registerRepairEvaluate(HttpServletRequest request) throws Exception{
        String clientUserId = request.getParameter("userId");
        String id= IdWorker.getId();
        String repUserId=request.getParameter("repUserId");
        String orderId=request.getParameter("orderId");
        String score=request.getParameter("score");
        String content=request.getParameter("content");
        String createTime= DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss");


        return repairEvaluateService.registerRepairEvaluate(request,id,clientUserId,repUserId,orderId,score,content,createTime);
    }

    /**
     * 根据订单Id查询评价信息
     * @param orderId
     * @return
     * @throws Exception
     */
    @RequestMapping("/wxApi/getEvaluateByOrderId")
    public Dto getEvaluateByOrderId(String orderId)throws Exception{
        Map<String, Object> map = new HashMap<>();
        map.put("orderId", orderId);
        return DtoUtil.returnSuccess("获取评价成功", repairEvaluateService.getRepairEvaluateListByMap(map).get(0));
    }


    /**
     * 电器厂pc  -- 评价接口
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("/dqcApi/saveRrepairEvaluate")
    @ResponseBody
    @Transactional
    public Dto saveRrepairEvaluate(HttpServletRequest request) throws Exception{
        String clientUserId = request.getParameter("userId");
        String id= IdWorker.getId();
        String repUserId=request.getParameter("repUserId");
        String orderId=request.getParameter("orderId");
        String score=request.getParameter("score");
        String content=request.getParameter("content");
        String createTime= DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss");


        return repairEvaluateService.registerRepairEvaluate(request,id,clientUserId,repUserId,orderId,score,content,createTime);
    }

}
